/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Tomas
 */
@Entity
@Table(name = "LOGIN_LOG")
@NamedQueries({
    @NamedQuery(name = "LoginLog.findAll", query = "SELECT l FROM LoginLog l")})
public class LoginLog implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected LoginLogPK loginLogPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 500)
    @Column(name = "IP")
    private String ip;
    @JoinColumn(name = "USER_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User appuser;

    public LoginLog() {
    }

    public LoginLog(LoginLogPK loginLogPK) {
        this.loginLogPK = loginLogPK;
    }

    public LoginLog(LoginLogPK loginLogPK, String ip) {
        this.loginLogPK = loginLogPK;
        this.ip = ip;
    }

    public LoginLog(Date date, long userId) {
        this.loginLogPK = new LoginLogPK(date, userId);
    }

    public LoginLogPK getLoginLogPK() {
        return loginLogPK;
    }

    public void setLoginLogPK(LoginLogPK loginLogPK) {
        this.loginLogPK = loginLogPK;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public User getAppuser() {
        return appuser;
    }

    public void setAppuser(User appuser) {
        this.appuser = appuser;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (loginLogPK != null ? loginLogPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LoginLog)) {
            return false;
        }
        LoginLog other = (LoginLog) object;
        if ((this.loginLogPK == null && other.loginLogPK != null) || (this.loginLogPK != null && !this.loginLogPK.equals(other.loginLogPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.LoginLog[ loginLogPK=" + loginLogPK + " ]";
    }
    
}
